package com.example.spareparts.controller;

import com.example.spareparts.entity.Supplier;
import com.example.spareparts.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/suppliers")
public class SupplierController {
    @Autowired
    private SupplierService supplierService;
    @GetMapping ("/listall")
    public List<Supplier> findAllSupplier()
    {
        return supplierService.findAllSupplier();
    }
    @PutMapping ("/update/{supplierid}")
    public void updateSupplier(@PathVariable Long supplierid, @RequestBody Supplier supplier){
        supplier.setSupplierid(supplierid);
        supplierService.updateSupplier(supplier);

    }
    @PostMapping ("/insert")
    public Supplier insertSupplier(@RequestBody Supplier supplier)
        {

            supplierService.insertSupplier(supplier);
            return supplier;
        }
    @DeleteMapping ("/delete/{supplierid}")
    public void deleteSupplier(@PathVariable Long supplierid)
    {
        supplierService.deleteSupplier(supplierid);
    }
    @GetMapping ("/findbyid/{supplierid}")
    public Supplier findSupplierById(@PathVariable Long supplierid)
    {
        return supplierService.findSupplierById(supplierid);
    }


}
